const express = require('express')
const cors = require('cors')
const crypto = require('crypto')
const app = express()
app.listen(3000)

const allowDomain = [
  'localhost:3000',
  'localhost:4000',
  'localhost:5000',
]

// 跨域
app.use((req, res, next) => {
  let allowCors = allowDomain.includes(req.headers.host)
  if (allowCors) {
    next()
  } else {
    res.send({ code: 2000, msg: '请求不允许' })
  }
})
app.use(cors())

/// 添加用户
app.get('/adduser', (req, res, next) => {
  // md5加密
  let pass = req.query.pass
  req.pass = crypto.createHash('md5').update(pass).digest('hex')
  // 向下执行
  next()
})
app.get('/adduser', (req, res) => {
  res.end(req.pass)
})



// app.use(cors())
// 定义路由
/* app.use(require('./router/userRouter'))
app.use(require('./router/artRouter')) */
app.use(require('./router'))